// FrameFuncs.cpp: implementation of the CFrameFuncs class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FrameFuncs.h"
#include "AnsiEditor.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFrameFuncs::CFrameFuncs()
{

}

CFrameFuncs::~CFrameFuncs()
{

}

void CFrameFuncs::LoadAccelerators(HACCEL *phAccel)
{
	ACCEL *pAccels;
	int	nAccels = 0;

	int nCommands = gnCommands;
	int nPluginCount = gpPluginManager->GetPluginCount();
	pAccels = new ACCEL[nCommands + nPluginCount];

	for(int n = 0; n < nCommands; ++n)
	{
		if(gCommands[n].key)
		{
			ACCEL accel;
			accel.cmd = (USHORT)gCommands[n].idCommand;
			accel.fVirt = gCommands[n].fVirt;
			accel.key = gCommands[n].key;
			pAccels[nAccels++] = accel;
		}
	}
	for(n = 0; n < nPluginCount; n++)
	{
		ACCEL accel;
		accel.cmd = (USHORT)(IDM_PLUGIN_BASE + n);
		CPlugin *pPlugin = gpPluginManager->GetPluginByIndex(n);
		accel.fVirt = pPlugin->m_fVirt;
		accel.key = pPlugin->m_key;
		pAccels[nAccels++] = accel;
	}

	HACCEL hAccel = CreateAcceleratorTable(pAccels, nAccels);
	if(*phAccel)
	{
		DestroyAcceleratorTable(*phAccel);
	}
	//m_hAccelTable = hAccel;
	*phAccel = hAccel;

	delete [] pAccels;
	
	UpdateCommandMap();

}